package org.xshop.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.xshop.model.SysFeedback;
import org.xshop.model.TMember;
import org.xshop.service.ISysFeedbackService;
import org.xshop.service.ITMemberService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import top.ibase4j.core.base.AppBaseController;
import top.ibase4j.core.util.DataUtil;
import top.ibase4j.core.util.WebUtil;

@Controller
@RequestMapping("/app/member/")
@Api(tags = "MemberFeedback", value = "个人中心-意见反馈", description = "APP-个人中心-意见反馈")
public class TMemberFeedBackController extends AppBaseController<SysFeedback, ISysFeedbackService> {
    @Autowired
    private ITMemberService memberService;

    @ApiOperation(value = "意见反馈", notes = "反馈用户意见", produces = MediaType.APPLICATION_JSON_VALUE, response = SysFeedback.class)
    @RequestMapping(value = "feedBack.api", method = {RequestMethod.POST})
    public Object saveFeedBackMessage(HttpServletRequest request, SysFeedback param) {
        param = WebUtil.getParameter(request, SysFeedback.class);
        Long id = getCurrUser(request);
        if (DataUtil.isNotEmpty(id)) {
            TMember result = memberService.getInfo(id);
            param.setUserName(result.getUserName() + "(" + result.getPhone() + ")");
        }
        Assert.notNull(param.getUserName(), "用户不能为空");
        Assert.notNull(param.getContent(), "意见反馈不能为空");
        return super.update(request, new ModelMap(), param);
    }
}
